﻿namespace Pathfinding
{
    using System;
    using System.Linq;
    using UnityEngine;

    internal class Program
    {
        private static void Main(string[] args)
        {
            double[] source = new double[0x3e8];
            Pathfinder pathfinder = new Pathfinder();
            for (int i = 0; i < 10; i++)
            {
                for (int k = 0; k < 10; k++)
                {
                    for (int m = 0; m < 1; m++)
                    {
                        if (((((i + k) + m) % 3) == 0) && (((i + k) + m) != 0))
                        {
                            pathfinder.MarkWalkable(new Point3D(i, k, m));
                        }
                        Point3D position = new Point3D(i, k, m);
                        Debug.DrawRay((Vector3) position, (Vector3) (Vector2.up * 0.1f), !pathfinder.IsPositionFree(position) ? Color.red : Color.white, 100f);
                    }
                }
            }
            for (int j = 0; j < source.Length; j++)
            {
                DateTime now = DateTime.Now;
                pathfinder.FindPath(Point3D.Zero, new Point3D(5, 8, 9));
                TimeSpan span = (TimeSpan) (DateTime.Now - now);
                source[j] = span.TotalMilliseconds;
            }
            Debug.Log("Total time: " + source.Sum().ToString() + "ms");
            Debug.Log("Average time: " + (source.Sum() / ((double) source.Length)) + "ms");
            Debug.Log("Max: " + source.Max() + "ms");
            Debug.Log("Min: " + source.Min() + "ms");
            Debug.Log("Output: ");
            SearchNode next = pathfinder.FindPath(Point3D.Zero, new Point3D(5, 8, 9));
            Debug.Log("Start: " + next.position.ToString());
            while (next.next != null)
            {
                Debug.DrawLine((Vector3) next.position, (Vector3) next.next.position, Color.yellow, 100f);
                Debug.Log("Route: " + next.next.position.ToString());
                next = next.next;
            }
            Debug.Log("Finished at: " + next.position.ToString());
        }
    }
}

